<?php

// TITLE: affiliated
// FILE: affiliated.php
// AUTHOR: dantira
// CREATED: Mar 21, 2015, 4:56:55 PM
?>

		public function createAffiliated($personId, $organizationId, $phone, $ext, $email, $startDate, $endDate, $status, $isEmployee) {
			global $con;
			$sql = 'INSERT INTO affiliated (person_id, organization_id, phone, ext, email, start_date, end_date, status, is_employee) VALUES (' . $personId . ', ' . $organizationId . ', ' . $phone . ', ' . $ext . ', ' . $email . ', ' . $startDate . ', ' . $endDate . ', ' . $status . ', ' . $isEmployee . ')';
			$this->open();
			$result = mysqli_query($con, $sql);
			$id = ($result) ? mysqli_insert_id($con) : $result;
			$this->close();
			return $id;
		}// end function

		public function readAffiliated($id) {
			global $con;
			$sql = 'SELECT * FROM affiliated WHERE id = ' . $id;
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$result = mysqli_fetch_array($results);
				$affiliated = new Affiliated();
				$affiliated->setPersonId($this->readPerson($result[0]));
				$affiliated->setOrganizationId($this->readOrganization($result[1]));
				$affiliated->setPhone($result[2]);
				$affiliated->setExt($result[3]);
				$affiliated->setEmail($result[4]);
				$affiliated->setStartDate($result[5]);
				$affiliated->setEndDate($result[6]);
				$affiliated->setStatus($result[7]);
				$affiliated->setIsEmployee($result[8]);
			} else {
				$affiliated = false;
			}
			return $affiliated;
		}// end function

		public function updateAffiliated($personId, $organizationId, $phone, $ext, $email, $startDate, $endDate, $status, $isEmployee) {
			global $con;
			$sql = 'UPDATE affiliated SET person_id = ' . $person_id . ', organization_id = ' . $organizationId . ', phone = ' . $phone . ', ext = ' . $ext . ', email = ' . $email . ', start_date = ' . $startDate . ', end_date = ' . $endDate . ', status = ' . $status . ', is_employee = ' . $isEmployee . ' WHERE id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function deleteAffiliated($id) {
			global $con;
			$sql = 'DELETE FROM affiliated WHERE person_id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function listAffiliated() {
			global $con;
			$sql = 'SELECT * FROM affiliated';
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$affiliateds = array();
				while ($result = mysqli_fetch_array($results)) {
					$affiliated = new Affiliated();
					$affiliated->setPersonId($this->readPerson($result[0]));
					$affiliated->setOrganizationId($this->readOrganization($result[1]));
					$affiliated->setPhone($result[2]);
					$affiliated->setExt($result[3]);
					$affiliated->setEmail($result[4]);
					$affiliated->setStartDate($result[5]);
					$affiliated->setEndDate($result[6]);
					$affiliated->setStatus($result[7]);
					$affiliated->setIsEmployee($result[8]);
					$affiliateds[] = $affiliated;
				}// end while
			} else {
				$affiliateds = false;
			}
			return $affiliateds;
		}// end function

